﻿CREATE PROCEDURE [ServiceEngine].[ListAssociatedEndpointsForOperationID]
	@OperationID uniqueidentifier
AS
BEGIN
	SET NOCOUNT ON;

	SELECT	N.[EntityID] as EndpointID, N.[EntityName] as URI
	FROM	[ServiceEngine].Endpoints_AssociatedOperations AO
	JOIN	[ServiceEngine].Names N on N.[EntityID] = AO.EndpointID and N.[EntityTypeID] = 2
	JOIN	[ServiceEngine].OperationVersions OV on OV.[OperationVersionID] = AO.[OperationVersionID]
	WHERE	OV.OperationID = @OperationID
	UNION
	SELECT	N.[EntityID] as EndpointID, N.[EntityName] as URI
	FROM	[ServiceEngine].Endpoints_PublishedOperations AO
	JOIN	[ServiceEngine].Names N on N.[EntityID] = AO.EndpointID and N.[EntityTypeID] = 2
	JOIN	[ServiceEngine].OperationVersions OV on OV.[OperationVersionID] = AO.[OperationVersionID]
	WHERE	OV.OperationID = @OperationID
END


